package engine.graphics.away3d
{
	import away3d.bounds.*;
	import away3d.cameras.*;
	import away3d.cameras.lenses.*;
	
	import engine.math.*;
	
	import flash.geom.*;

	public class RxCamera3D extends Camera3D
	{	
		private var m_position:RxVector4;
		private var m_xAxis:RxVector4;
		private var m_yAxis:RxVector4;
		private var m_zAxis:RxVector4;
		private var m_viewMatrix:RxMatrix4x4;
		private var m_projMatrix:RxMatrix4x4;
		private var m_viewProjMatrix:RxMatrix4x4;
		private var m_viewMatrixTransposed:RxMatrix4x4;
		private var m_projMatrixTransposed:RxMatrix4x4;
		private var m_viewProjMatrixTransposed:RxMatrix4x4;
		private var m_viewMatrixInverse:RxMatrix4x4;
		private var m_projMatrixInverse:RxMatrix4x4;
		private var m_viewProjMatrixInverse:RxMatrix4x4;
		private var m_pitchMatrix:RxMatrix4x4;
		private var m_viewportRect:Rectangle;
		private var m_viewportScaleOffset:RxVector4;
		private var m_frustumPlanes:Vector.<RxPlane>;
		private var m_cornerDiagScales:Vector.<RxVector4>;
		private var m_cornerPoints:Vector.<RxVector4>;
		
		public function RxCamera3D(les:LensBase)
		{
			super(les);
			
			this.m_position = new RxVector4(0, 0, 0, 1);
			this.m_xAxis = new RxVector4(1, 0, 0, 0);
			this.m_yAxis = new RxVector4(0, 1, 0, 0);
			this.m_zAxis = new RxVector4(0, 0, 1, 0);
			this.m_viewMatrix = new RxMatrix4x4();
			this.m_projMatrix = new RxMatrix4x4();
			this.m_viewProjMatrix = new RxMatrix4x4();
			this.m_viewMatrixTransposed = new RxMatrix4x4();
			this.m_projMatrixTransposed = new RxMatrix4x4();
			this.m_viewProjMatrixTransposed = new RxMatrix4x4();
			this.m_viewMatrixInverse = new RxMatrix4x4();
			this.m_projMatrixInverse = new RxMatrix4x4();
			this.m_viewProjMatrixInverse = new RxMatrix4x4();
			this.m_pitchMatrix = new RxMatrix4x4();
			this.m_viewportRect = new Rectangle(0, 0, 1, 1);
			this.m_viewportScaleOffset = new RxVector4(1, 1, 0, 0);
			this.m_frustumPlanes = new Vector.<RxPlane>(6, true);
			this.m_frustumPlanes[0] = new RxPlane(0, 0, 0, 0);
			this.m_frustumPlanes[1] = new RxPlane(0, 0, 0, 0);
			this.m_frustumPlanes[2] = new RxPlane(0, 0, 0, 0);
			this.m_frustumPlanes[3] = new RxPlane(0, 0, 0, 0);
			this.m_frustumPlanes[4] = new RxPlane(0, 0, 0, 0);
			this.m_frustumPlanes[5] = new RxPlane(0, 0, 0, 0);
			this.m_cornerDiagScales = new Vector.<RxVector4>(8, true);
			this.m_cornerDiagScales[0] = new RxVector4(-1, -1, -1, 0);
			this.m_cornerDiagScales[1] = new RxVector4(1, -1, -1, 0);
			this.m_cornerDiagScales[2] = new RxVector4(-1, 1, -1, 0);
			this.m_cornerDiagScales[3] = new RxVector4(1, 1, -1, 0);
			this.m_cornerDiagScales[4] = new RxVector4(-1, -1, 1, 0);
			this.m_cornerDiagScales[5] = new RxVector4(1, -1, 1, 0);
			this.m_cornerDiagScales[6] = new RxVector4(-1, 1, 1, 0);
			this.m_cornerDiagScales[7] = new RxVector4(1, 1, 1, 0);
			this.m_cornerPoints = new Vector.<RxVector4>(8, true);
			this.m_cornerPoints[0] = new RxVector4(0, 0, 0, 1);
			this.m_cornerPoints[1] = new RxVector4(0, 0, 0, 1);
			this.m_cornerPoints[2] = new RxVector4(0, 0, 0, 1);
			this.m_cornerPoints[3] = new RxVector4(0, 0, 0, 1);
			this.m_cornerPoints[4] = new RxVector4(0, 0, 0, 1);
			this.m_cornerPoints[5] = new RxVector4(0, 0, 0, 1);
			this.m_cornerPoints[6] = new RxVector4(0, 0, 0, 1);
			this.m_cornerPoints[7] = new RxVector4(0, 0, 0, 1);
		}
		
		public static function CreateOrthoViewProjectionMatrix(planes:RxMatrix4x4, matrix:RxMatrix4x4, param3:RxVector4, param4:Number, param5:Number, param6:Number, param7:Number, param8:Number, param9:Number, param10:Number) : void
		{
			planes.ViewFromRotations(param3, param4, param5, param6);
			matrix.OrthoCenteredRightHanded(param7, param8, param9, param10, true);
		}
		
		public static function CreateFrustumPlanes(planes:Vector.<RxPlane>, matrix:RxMatrix4x4) : void
		{
			var plane:RxPlane = null;
			var i:uint = 0;
			plane = planes[0];
			plane.v.x = matrix.m03 + matrix.m00;
			plane.v.y = matrix.m13 + matrix.m10;
			plane.v.z = matrix.m23 + matrix.m20;
			plane.v.w = matrix.m33 + matrix.m30;
			plane = planes[1];
			plane.v.x = matrix.m03 - matrix.m00;
			plane.v.y = matrix.m13 - matrix.m10;
			plane.v.z = matrix.m23 - matrix.m20;
			plane.v.w = matrix.m33 - matrix.m30;
			plane = planes[2];
			plane.v.x = matrix.m03 + matrix.m01;
			plane.v.y = matrix.m13 + matrix.m11;
			plane.v.z = matrix.m23 + matrix.m21;
			plane.v.w = matrix.m33 + matrix.m31;
			plane = planes[3];
			plane.v.x = matrix.m03 - matrix.m01;
			plane.v.y = matrix.m13 - matrix.m11;
			plane.v.z = matrix.m23 - matrix.m21;
			plane.v.w = matrix.m33 - matrix.m31;
			plane = planes[4];
			plane.v.x = matrix.m03 + matrix.m02;
			plane.v.y = matrix.m13 + matrix.m12;
			plane.v.z = matrix.m23 + matrix.m22;
			plane.v.w = matrix.m33 + matrix.m32;
			plane = planes[5];
			plane.v.x = matrix.m03 - matrix.m02;
			plane.v.y = matrix.m13 - matrix.m12;
			plane.v.z = matrix.m23 - matrix.m22;
			plane.v.w = matrix.m33 - matrix.m32;
			i = 0;
			while (i < 6)
			{
				
				planes[i].Normalize();
				i = i + 1;
			}
		}
		
		public function GetPosition() : RxVector4
		{
			return this.m_position;
		}
		
		public function GetXAxis() : RxVector4
		{
			return this.m_xAxis;
		}
		
		public function GetYAxis() : RxVector4
		{
			return this.m_yAxis;
		}
		
		public function GetZAxis() : RxVector4
		{
			return this.m_zAxis;
		}
		
		public function GetViewMatrix() : RxMatrix4x4
		{
			return this.m_viewMatrix;
		}
		
		public function GetProjMatrix() : RxMatrix4x4
		{
			return this.m_projMatrix;
		}
		
		public function GetViewProjMatrix() : RxMatrix4x4
		{
			return this.m_viewProjMatrix;
		}
		
		public function GetViewMatrixTransposed() : RxMatrix4x4
		{
			return this.m_viewMatrixTransposed;
		}
		
		public function GetProjMatrixTransposed() : RxMatrix4x4
		{
			return this.m_projMatrixTransposed;
		}
		
		public function GetViewProjMatrixTransposed() : RxMatrix4x4
		{
			return this.m_viewProjMatrixTransposed;
		}
		
		public function GetViewMatrixInverse() : RxMatrix4x4
		{
			return this.m_viewMatrixInverse;
		}
		
		public function GetProjMatrixInverse() : RxMatrix4x4
		{
			return this.m_projMatrixInverse;
		}
		
		public function GetViewProjMatrixInverse() : RxMatrix4x4
		{
			return this.m_viewProjMatrixInverse;
		}
		
		public function GetPitchMatrix() : RxMatrix4x4
		{
			return this.m_pitchMatrix;
		}
		
		public function GetFrustumPlanes() : Vector.<RxPlane>
		{
			return this.m_frustumPlanes;
		}
		
	}
}